Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

237
Visualizações
Whats the best way to convert an integer to a string in the context of making a "Loot" simulator?

I'm a beginner in Javascript so please bare with me. What I have setup so far is a simple 6 sided dice. My goal is to assign each "side" to a number so that for instance if I roll a '6' , the 6 will print and have a value of "Dharoks Platebody".


    document.querySelector('#roll').addEventListener('click', roll)
    
    let num = 6
    
    function roll() {
    let diceRoll = Math.floor( Math.random() * 6 + 1)
    
    num.toString('Dharoks Platebody')
    alert(num)
    }

This is what I have so far but it returns the error "radix argument must be between 2 and 36" . Now obviously I could and likely will research that particular error more but my real question here is what is the most efficient way to go about this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You are probably looking for an array:

const values = [
    "value if 1",
    "value if 2",
    "value if 3",
    "value if 4",
    "value if 5",
    "value if 6",
];

const num = Math.floor(Math.random() * 6) + 1;

alert(num);

alert(values[num - 1]);

There is a - 1 there because array indices start counting from 0. So the first item in the array would be the "0th position", and so on.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda